package com.xysd.examproject.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.xysd.examproject.R;
import com.xysd.examproject.util.animation.EasyTransition;
import com.xysd.examproject.util.animation.EasyTransitionOptions;

import org.xutils.common.Callback;
import org.xutils.image.ImageOptions;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

public class LaunchActivity extends Activity implements View.OnClickListener {


    @ViewInject(R.id.iconImg)
    private ImageView iconImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launch);
        x.view().inject(this);
        init();
    }

    private void init() {
        iconImg.setOnClickListener(this);
    }

    private void jump() {
        EasyTransitionOptions options=EasyTransitionOptions.makeTransitionOptions(LaunchActivity.this,findViewById(R.id.iconImg));
        Intent intent=new Intent(this,MainActivity.class);
        EasyTransition.startActivity(intent,options);

    }

    private void setImg() {
        Drawable drawable=getResources().getDrawable(R.mipmap.loading);
        ImageOptions.Builder builder=new ImageOptions.Builder();
        builder.setFadeIn(true).
                setLoadingDrawable(drawable);
        ImageOptions imageOptions=builder.build();
//        x.image().bind(iconImg,"https://maxcdn.icons8.com/Share/icon/ios7/Cinema//anonymous_mask1600.png");
            x.image().loadDrawable("https://maxcdn.icons8.com/Share/icon/ios7/Cinema//anonymous_mask1600.png", imageOptions, new Callback.CommonCallback<Drawable>() {
                @Override
                public void onSuccess(Drawable result) {
                    Log.i("onSuccess",result.toString());
                    iconImg.setImageDrawable(result);
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {
                    Log.i("onError",isOnCallback+"");
                }

                @Override
                public void onCancelled(CancelledException cex) {
                    Log.i("onCancelled",cex+"");
                }

                @Override
                public void onFinished() {
                    Log.i("onFinished","onFinished");
                    jump();
                }
            });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iconImg:
                jump();
//                setImg();
                break;
            default:
                break;
        }
    }
}
